let img_player = new Image();
img_player.loaded = false;
img_player.src = 'imgs/role.png';
img_player.onload = function () {
    img_player.loaded = true;
};

const DIR = {
   N:1,
   NW:2,
   W:3,
   SW:4,
   S:5,
   SE:6,
   E:7,
   NE:8
};

class Player {
    constructor() {
        this.dir = DIR.S;
        this.x = 0;
        this.y = 0;
        this.width = 90;
        this.height = 140;
    }

    draw(ctx) {
        const w = 90;
        let offx = 0;
        let offy = 0;
        switch (this.dir) {
            case DIR.N:
                offx = w * 5;
                break;
            case DIR.NW:
                offx = w * 4;
                break;
            case DIR.W:
                offx = w * 3;
                break;
            case DIR.SW:
                offx = w * 2;
                break;
            case DIR.S:
                offx = w;
                break;
            case DIR.SE:
                offx = 0;
                break;
            case DIR.E:
                offx = w * 7;
                break;
            case DIR.NE:
                offx = w * 6;
                break;
        }

        if(img_player.loaded){
            ctx.drawImage(img_player,
                offx,offy,this.width,this.height,
                this.x,this.y,this.width,this.height);
        }
    }

    setDir(newDir){
        this.dir = newDir;
    }

    update(){

    }
}
